/*
 * @Author: LVGRAPE
 * @LastEditors: LVGRAPE
 */
#include "at32f4xx.h"
#include "delay.h" 
#include <stdbool.h>
//#include "LED.h"
// __IO uint32_t systick_cnt = 0;
// __IO uint32_t systick_us = 0;
//__IO uint32_t systick_ms = 0;

//systick millis
__IO uint32_t systick_cnt_ms = 0;
bool msUpdate;
//__IO uint32_t systick_cnt_s = 0;
// volatile void delay_us(uint16_t us)
// {
// 	systick_us = us;
// 	while (systick_us > 0) ;
// }
void delay_ms(uint32_t ms)
{
	uint32_t now=systick_cnt_ms;
	while ((now+ms) > systick_cnt_ms);
	// {
	// 	/* code */
	// }
	
	// while(ms--)
	// {
	// 	msUpdate = 1;
	// 	while(msUpdate);
	// }
		// delay_us(1000);
}
void SysTick_Init(uint32_t div)//set number of ticks between two interruption
{
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);//150MHz
	SysTick_Config(div);
}
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
	// if (systick_us > 0) systick_us--;

	// systick_cnt++;
	// if (systick_cnt > 999)
	// {
		// msUpdate=0;
		systick_cnt_ms++;
	// 	systick_cnt = 0;
	// }
}